favorite_languages = {
    'jen': 'python',
    'sarah': 'c',
    'edward': 'ruby',
    'phil': 'python',
}

friend = ['phil', 'sarah']

for name in favorite_languages.keys():
    print(f'Hi {name.title()}!')

    if name in friend:
        print(f"\t{name.title()}, I see you love {favorite_languages[name].title()}.")

if 'erin' not in favorite_languages.keys():
    print("Erin, please take our pull!")

for name in sorted(favorite_languages.keys()): # sorted(list)返回排序后副本，不改变原顺序
    print(f"{name.title()}")
print(favorite_languages.keys())

for language in set(favorite_languages.values()): # set()提取出不重复的部分组成一个列表
    print(language, end=' ')
print()
language_list = set(favorite_languages.values())
print(language_list)

# 也可使用{}直接创建集合set，同样会剔除重复元素
language_list = {'python', 'c', 'python'}
print(language_list)


# 字典值为列表
favorite_languages = {
    'jen': ['python'],
    'sarah': ['c'],
    'edward': ['ruby'],
    'phil': ['python', 'c'],
}

for name, languages in favorite_languages.items():
    if len(languages) == 1:
        print(f"{name}'s favoritelanguages is: {languages[0]}", end = '')
    else:
        print(f"{name}'s favoritelanguages are: ", end = '')
        for language in languages: # 如果是单一个字符串，就会被识别为字符列表
            print(language,end=' ')
    print()